package com.ruoyi.resturant.service.impl;
import com.ruoyi.common.exception.BizException;
import com.ruoyi.resturant.domain.ResShop;
import com.ruoyi.resturant.mapper.ResShopMapper;
import com.ruoyi.resturant.service.IResShopService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
    /**
     * 店铺Service业务层处理
     *
     * @author Daniel
     * @date 2023-09-27
     */
    @Service
    public class ResShopServiceImpl implements IResShopService
    {
        private static final Logger log = LoggerFactory.getLogger( ResShopServiceImpl.class);
        @Autowired
        private ResShopMapper resShopMapper;

        /**
         * 查询店铺
         *
         * @param id 店铺主键
         * @return 店铺
         */
        @Override
        public ResShop selectResShopById(Long id)
        {
            return resShopMapper.selectResShopById(id);
        }
        /**
         * 查询店铺列表
         *
         * @param shopName 商铺名称
         * @return 店铺
         */
        @Override
        public List<ResShop> selectResShopByParam(String shopName)
        {

            return resShopMapper.selectResShopByParam(shopName);
        }


        /**
         * 新增店铺
         *
         * @param resShop 店铺
         * @return 结果
         */
        @Override
        public int insertResShop(ResShop resShop)
        {
            // TODO 0：插入成功
            return resShopMapper.insertResShop(resShop);
        }

        /**
         * 修改店铺
         *
         * @param resShop 店铺
         * @return 结果
         */
        @Override
        public int updateResShop(ResShop resShop)
        {

            // TODO 0：更新成功
            return resShopMapper.updateResShop(resShop);
        }


        /**
         * 删除店铺信息
         *
         * @param id 店铺主键
         * @return 结果
         */
        @Override
        public int deleteResShopById(Long id)
        {
            ResShop resShop =resShopMapper.selectResShopById(id);
//        如果学生不存在的话抛出异常
            if (resShop == null){
                throw new BizException(404,"该店铺ID"+id+"不存在");
            }
            log.info("该店铺id"+id+"存在");
            // TODO 0：删除成功
            return resShopMapper.deleteResShopById(id);
        }
    }


